﻿/*
功能: 收集表单数据,封装在一个json对象中,
最后返回一个json对象
*/
function collectData() {
    var data = new Object();
    //角色id
    data.roleId = jQuery("#roleId").val();

    //权限id 数组
    var powerIds = new Array();
    var checkBoxes = document.getElementsByName("powerId");
    for (var i in checkBoxes) {
        if (checkBoxes[i].checked) {
            powerIds.push(checkBoxes[i].value);
        }
    }
    data.powerIds = powerIds.toString();
    return data;
}
function grantPowerToUser() {
    var data = collectData();
//    alert(data.roleId);
//    alert(data.powerIds);
    var url = "/User/GrantPowerToUser";
    jQuery.ajax({
        url: url,
        data: data,
        type: "POST",
        dataType: "json",
        success: function onSuccess(data) {
            if (data.errors.length > 0) {
                alert("[系统提示:]\n\t授时出错!\n"+data.errors.toString());
            }
            else {
                alert("[系统提示:]\n\t授权成功!");
            }
        },
        error: function onError() {
            alert("请求失败");
        }
    });
}
function selectAllPower(obj) {
    var flag = jQuery(obj).attr("flag");
    if (flag == 1) {
        jQuery("input[name='powerId']").attr("checked", true);
        jQuery(obj).attr("flag", 2);
        jQuery(obj).attr("value", "取消");
    }
    else {
        jQuery("input[name='powerId']").attr("checked", false);
        jQuery(obj).attr("flag", 1);
        jQuery(obj).attr("value", "全选");
    }
}